package com.sky.controller.admin;


import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.SetmealService;
import com.sky.vo.SetmealVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@Api(tags = "套餐相关")
@RequestMapping("/admin/setmeal")
public class SetmealController {

    @Autowired
    private SetmealService setmealService;


    @GetMapping("/page")
    @ApiOperation("菜品分页查询")
    public Result<PageResult> List(SetmealPageQueryDTO setmealPageQueryDTO) {
        log.info("菜品分页查询:{}",setmealPageQueryDTO);
        PageResult pageResult = setmealService.List(setmealPageQueryDTO);
        return Result.success(pageResult);
    }

    @PostMapping("/status/{status}")
    @ApiOperation("套餐启用停用")
    public Result updateStatus(@PathVariable Integer status,Long id) {
        log.info("套餐启用停用:{},{}",status,id);
        setmealService.updateStatus(status,id);
        return Result.success();
    }
    @GetMapping("/{id}")
    @ApiOperation("根据id查询套餐")
    public Result<SetmealVO> getSetmealById(@PathVariable Long id) {
        log.info("根据id查询套餐:{}",id);
        SetmealVO setmealVO = setmealService.getSetmealById(id);
        return Result.success(setmealVO);
    }


    @PutMapping
    @ApiOperation("根据id修改套餐")
    public Result updateById(@RequestBody SetmealDTO setmealDTO) {
        log.info("根据id修改套餐：{}",setmealDTO);
        setmealService.updateById(setmealDTO);
        return Result.success();
    }

    @DeleteMapping
    @ApiOperation("根据id批量删除套餐")
    public Result deleteSetmealByIds(@RequestParam List<Long> ids)
    {
        log.info("根据id批量删除套餐:{}",ids);
        setmealService.deleteSetmealByIds(ids);
        return Result.success();


    }
    @PostMapping
    @ApiOperation("新增套餐")
    public Result addSetmeal(@RequestBody SetmealDTO setmealDTO) {
        log.info("新增套餐：{}",setmealDTO);
        setmealService.add(setmealDTO);
        return Result.success();
    }
}


